/*
 * @Author: 严晗 823841034@qq.com
 * @Date: 2023-11-06 09:22:58
 * @LastEditors: 严晗 823841034@qq.com
 * @LastEditTime: 2023-11-08 16:46:36
 * @FilePath: /yike-admin/Users/yanhan/vite-project/src/store/dic.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { getSaleList, getCompanyAreaList } from '~/api/dic'

const dic = {
	state: {
		salesData: [],
		companyAreaData: [],
	},
	mutations: {
		// 设置销售数据
		SET_SALES_DATA(state, salesData) {
			state.salesData = salesData
		},
		// 设置公司区域数据
		SET_COMPANY_AREA_DATA(state, companyAreaData) {
			state.companyAreaData = companyAreaData
		},
	},
	actions: {
		// 获取销售数据
		getSalesData({ commit }) {
			return new Promise((resolve, reject) => {
				getSaleList()
					.then((res) => {
						let data = []
						res.data.data.forEach((item) => {
							let params = {
								label: item.name,
								value: item.userId,
							}
							data.push(params)
						})
						commit('SET_SALES_DATA', data)
						resolve(data)
					})
					.catch((err) => {
						reject(err)
					})
			})
		},
		// 获取公司区域数据
		getCompanyAreaData({ commit }) {
			return new Promise((resolve, reject) => {
				getCompanyAreaList()
					.then((res) => {
						commit('SET_COMPANY_AREA_DATA', res.data.data)
						resolve(res.data.data)
					})
					.catch((err) => {
						reject(err)
					})
			})
		},
	},
}

export default dic
